package com.youlai.system.controller;

import com.youlai.system.common.annotation.Log;
import com.youlai.system.common.enums.BusinessTypeEnum;
import com.youlai.system.common.enums.ModuleEnum;
import com.youlai.system.common.result.PageResult;
import com.youlai.system.common.util.ExcelUtils;
import com.youlai.system.model.query.SysOperLogQuery;
import com.youlai.system.model.vo.SysLogExportVO;
import com.youlai.system.model.vo.SysOperLogVO;
import com.youlai.system.service.SysLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Tag(name = "08.操作日志表")
@RestController
@RequestMapping("/api/v1/logs/oper")
@RequiredArgsConstructor
public class SysOperLogController {


    private final SysLogService sysLogService;

    /**
     * 列表请求
     * @param query 日志列表对象
     * @return 请求列表
     */
    @Operation(summary = "操作日志分页列表")
    @GetMapping("/page")
    public PageResult<SysOperLogVO> page(SysOperLogQuery query) {
        return PageResult.success(sysLogService.pageLog(query));
    }


    @Operation(summary = "导出操作日志")
    @GetMapping("/export")
    @Log(module = ModuleEnum.OPER_LOG, title = "导出操作日志", businessType = BusinessTypeEnum.EXPORT)
    public void exportUsers(SysOperLogQuery queryParams, HttpServletResponse response) throws IOException {
        List<SysLogExportVO> exportLogList = sysLogService.listExportLogs(queryParams);
        ExcelUtils.export(response, SysLogExportVO.class, exportLogList, "操作日志列表");
    }

}
